#include <iostream>
#include <cmath>
#include "BinaryTree.h"
using namespace std;

// 100.00 %
class Solution
{
  public:
	int minDepth(TreeNode *root)
	{
		if (root)
		{
			int l = minDepth(root->left);
			int r = minDepth(root->right);
			if (l == 0)
				return 1 + r;
			if (r == 0)
				return 1 + l;
			return 1 + min(l, r);
		}
		return 0;
	}
};

int main()
{
	int arr[] = {3, 9, 0, 0, 20, 15, 0, 0, 7, 0, 0};
	int n = sizeof(arr) / sizeof(arr[0]);
	TreeNode *tree = createBinaryTree(arr, n);
	preorderPrint(tree);
	cout << endl;
	cout << "deep=" << Solution().minDepth(tree) << endl;
	return 0;
}
